require('../../assets/css/index.less');
// 当前页面样式
require('./login.less');

// 工具函数 utils
const dom = require('../../utils/dom');
// ajax
var https = require("../../utils/https");
var local = require("../../utils/local");
// 验证
const validator = require('../../utils/validator');
var { isAcount, ispwd } = validator;
dom.ready(function() {
    var btn = document.querySelector(".log");
    var account = document.querySelector(".usename");
    var password = document.querySelector(".pwd");
    btn.addEventListener("click", () => {
        if (account.value && password.value) {
            https.post("/api/user/login", {
                account: account.value,
                password: password.value
            }, function(res) {
                var { errno, data } = res;
                if (errno == 0) {
                    alert("登录成功")
                        // local.set("user", data)
                    local.set("tk", data.token)
                        // console.log(1111);
                    location.href = "./home.html"
                } else {
                    alert("登陆失败，请检查账号或密码")
                }
            })
        } else {
            alert("账号或密码不能为空");
        }
    })
})